
package com.trydofor.id.a9cq;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

import javax.annotation.Nonnull;

import com.trydofor.id.core.A9CQ;
import com.trydofor.id.core.ApiExceptions;

/**
 * an agent integer a9cq of long a9cq
 * 
 * @author : Shi Rongjiu (www.trydofor.com)
 */
public final class AgentIntegerA9cq implements A9CQ<Integer> {
    
    private final A9CQ<Long> longA9cq;
    
    /**
     * an agent integer a9cq of long a9cq
     * 
     * @param a9cq @Nonnull the increment.
     * @return @Nonnull an agent integer a9cq
     * @throws NullPointerException if a9cq is null
     */
    @Nonnull
    public static AgentIntegerA9cq wrap(@Nonnull A9CQ<Long> a9cq) {
        ApiExceptions.checkNullPointer(a9cq);
        return new AgentIntegerA9cq(a9cq);
    }
    
    private AgentIntegerA9cq(A9CQ<Long> a9cq) {
        this.longA9cq = a9cq;
    }
    
    /**
     * an wrapped method
     * 
     * {@inheritDoc}
     * 
     * @see FixedLongA9cq#isAtomic()
     */
    public boolean isAtomic() {
        return longA9cq.isAtomic();
    }
    
    /**
     * an wrapped method
     * 
     * {@inheritDoc}
     * 
     * @see FixedLongA9cq#remains()
     */
    public long remains() {
        return longA9cq.remains();
    }
    
    /**
     * an wrapped method
     * 
     * {@inheritDoc}
     * 
     * @see FixedLongA9cq#current()
     */
    public Integer current() {
        Long r = longA9cq.current();
        return r == null ? null : Integer.valueOf(r.intValue());
    }
    
    /**
     * an wrapped method
     * 
     * {@inheritDoc}
     * 
     * @see FixedLongA9cq#next()
     */
    public Integer next() {
        Long r = longA9cq.next();
        return r == null ? null : Integer.valueOf(r.intValue());
    }
    
    /**
     * an wrapped method
     * 
     * {@inheritDoc}
     * 
     * @see FixedLongA9cq#next(long, TimeUnit)
     */
    public Integer next(long timeout, TimeUnit unit) throws InterruptedException, TimeoutException {
        Long r = longA9cq.next(timeout, unit);
        return r == null ? null : Integer.valueOf(r.intValue());
    }
    
    /**
     * an wrapped method
     * 
     * {@inheritDoc}
     * 
     * @see FixedLongA9cq#reset()
     */
    public void reset() {
        longA9cq.reset();
    }
    
    /**
     * an wrapped method
     * 
     * {@inheritDoc}
     * 
     * @see FixedLongA9cq#toString()
     */
    public String toString() {
        return longA9cq.toString();
    }
}
